﻿#include <libini/explain.h>
#include <libini/string.h>


// constructor
Xanadu::ini::explain::explain() noexcept
{
	this->_memberText = "";
}

// constructor
Xanadu::ini::explain::explain(const std::string& _String) noexcept
{
	this->_memberText = _String;
}

// constructor
Xanadu::ini::explain::explain(const Xanadu::ini::explain& _Other) noexcept
{
	this->_memberText = _Other._memberText;
}

// destructor
Xanadu::ini::explain::~explain() noexcept
{
}



// operator overload =
Xanadu::ini::explain& Xanadu::ini::explain::operator = (const std::string& _String) noexcept
{
	this->_memberText = _String;
	return *this;
}

// operator overload =
Xanadu::ini::explain& Xanadu::ini::explain::operator = (const Xanadu::ini::explain& _Other) noexcept
{
	this->_memberText = _Other._memberText;
	return *this;
}



// Get text
std::string Xanadu::ini::explain::text() const noexcept
{
	return this->_memberText;
}



// Convert to string
std::string Xanadu::ini::explain::toString() const noexcept
{
	if(this->_memberText.empty())
	{
		return this->_memberText;
	}
	else
	{
		if(this->_memberText[0] == LIBINI_EXPLAIN_CHAR)
		{
			return this->_memberText;
		}
		return std::string(";") + this->_memberText;
	}
}

// Convert to string
std::string Xanadu::ini::explain::toString(const std::list<Xanadu::ini::explain>& _Items) noexcept
{
	auto		vString = std::string();
	for(const auto & vItem : _Items)
	{
		vString += vItem.toString();
		vString += LIBINI_NEWLINE_STRING;
	}
	return vString;
}

// Format from one or more lines of string
std::list<Xanadu::ini::explain> Xanadu::ini::explain::fromString(const std::string& _String) noexcept
{
	return Xanadu::ini::explain::fromString(Xanadu::ini::string::split(_String, LIBINI_NEWLINE_STRING));
}

// Format from one or more lines of string
std::list<Xanadu::ini::explain> Xanadu::ini::explain::fromString(const std::list<std::string>& _String) noexcept
{
	auto		vItems = std::list<Xanadu::ini::explain>();
	for(const auto & vItem : _String)
	{
		vItems.emplace_back(vItem);
	}
	return vItems;
}
